import Vue from 'vue'
import App from './App'
import store from './store'
import Title from './components/uni-nav-bar/uni-nav-bar'
import Content from './components/uni-content/uni-content'
import Foot from './components/uni-foot/uni-foot'
Vue.config.productionTip = false
Vue.prototype.$go = function(url,type) {
	if(type){
		if(!this.$store.state.user){
			// uni.showToast({
			// 	title: '请登录后重试！',
			// 	icon: 'none',
			// 	duration: 1500
			// 	// position:'top'
			// });
			uni.navigateTo({
				url: '/pages/login/login'
			});
			return;
		}
	};
	// console.log(url)
	uni.navigateTo({
		url: url
	});
}
Vue.prototype.resetstr = function(str) { //截取小数点前两位
			if (!str) str = '0';
			str = str +'';
			if (str.indexOf('.') != -1) {
				var newstr = (str + '').split('.');
				str = newstr[0] + '.' + newstr[1].substr(0, 3);
			};
			return str;
		};
Vue.prototype.getUrlParam = function(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg); //匹配目标参数
	if (r != null) return unescape(r[2]);
	return null; //返回参数值
};
Vue.prototype.getdatas = function(obj) {
	if (!obj.json) obj.json = {};
	uni.request({
		url: obj.url,
		method: obj.type ? obj.type : 'get',
		data: obj.json,
		success: function(arg) {
			// arg = JSON.parse(arg);
			obj.fun(arg);
		},
		fail: res => {
			console.log(obj.url + '错误' + res);
		}
	});
}
Vue.prototype.gettoken = function() { //获取cookie
	var arr, reg = new RegExp("(^| )" + 'token' + "=([^;]*)(;|$)");
	if (arr = document.cookie.match(reg)) {
		return unescape(arr[2]);
	} else {
		return null;
	}
};
Vue.prototype.getparam = function() {
	let url = location.href.split('?');
	let params = [];
	if (url && url[1]) {
		let p = url[1].split('&');
		for (let i = 0; i < p.length; i++) {
			let kv = p[i].split('=');
			params[kv[0]] = kv[1];
		}
	}
	return name ? params[name] : params;
};
Vue.prototype.getDay = function(day) {

	var today = new Date();

	var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;

	today.setTime(targetday_milliseconds); //注意，这行是关键代码

	var tYear = today.getFullYear();

	var tMonth = today.getMonth();

	var tDate = today.getDate();

	tMonth = this.doHandleMonth(tMonth + 1);

	tDate = this.doHandleMonth(tDate);

	return tYear + "-" + tMonth + "-" + tDate;

};
Vue.prototype.doHandleMonth = function doHandleMonth(month) {

	var m = month;

	if (month.toString().length == 1) {

		m = "0" + month;

	}

	return m;

};
Vue.component('Title', Title);
Vue.component('Content', Content);
Vue.component('Foot', Foot);
App.mpType = 'app'
// console.log(JSON.stringify(App))
const app = new Vue({
	...App,
	store
})
app.$mount()
